// pages/dis-centers/dis-center.js
var http = require("../../utils/http.js");
Page({
  /**
   * 页面的初始数据
   */
  data: {
    "unsettledAmount": 0, // 待结算金额
    "settledAmount": 0, // 可提现金额
    "invalidAmount": 0, // 已失效金额
    "addupAmount": 0, // 累计收益
    disNotice: [], // 分销公告
    distInfo: {}
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {
    this.getDistributionMsg()
    this.setData({
      distInfo:wx.getStorageSync("distInfo")
    })
  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {
    this.getDisInfoData()
  },

  // 获取分销公告
  getDistributionMsg: function () {
    var ths = this
    var params = {
      url: '/p/distribution/msg/page',
      method: 'GET',
      data: {
        // current: 1,
        isTop: 1,
        // size: 10
      },
      callBack: res => {
        console.log(res)
        ths.setData({
          disNotice: res.records
        })
      }
    }
    http.request(params)

  },


  // 跳转到分销员等级页面
  toSalesmanLevel() {
    console.log('跳转到分销等级')
    wx.navigateTo({
      url: '/pages/salesmanLevel/salesmanLevel'
    })
  },
  // 跳转到公告页面
  toNotice() {
    if(this.data.disNotice.length > 0) {
      wx.navigateTo({
        url: '/pages/recent-news/recent-news?isDist=' + true,
      })
    }
  },
  /**
   * 获取用户钱包数据
   */
  getDisInfoData: function() {
    wx.showLoading();
    var params = {
      url: "/p/distribution/user/info",
      method: "GET",
      data: {
        shopId: 1
      },
      callBack: res => {
        this.setData({
          settledAmount: res.distributionUserWallet.settledAmount,
          addupAmount: res.distributionUserWallet.addupAmount
        });
        wx.hideLoading();
      }
    }
    http.request(params);
  },
  /**
   * 跳转收入明细
   */
  toIncomeDetailsPage: function() {
    wx.navigateTo({
      url: '/pages/income-details/income-details',
    })
  },
  /**
   * 跳转体现记录
   */
  toWalletCashPage: function() {
    wx.navigateTo({
      url: '/pages/take-notes/take-notes',
    })
  },
  /**
   * 跳转体现规则
   */
  toWalletCashRulePage: function() {
    wx.navigateTo({
      url: '/pages/draw-rule/draw-rule',
    })
  },
  /**
   * 跳转至我的用户
   */
  toMyUserPage: function() {
    wx.navigateTo({
      url: '/pages/my-users/my-users',
    })
  },
  /**
   * 跳转我的推广界面
   */
  toPromotionOrderPage: function() {
    wx.navigateTo({
      url: '/pages/promotion-order/promotion-order',
    })
  },

  /**
   * 跳转我的推广商品
   */
  toPromotionProdPage: function() {
    wx.navigateTo({
      url: '/pages/promotionProd/promotionProd',
    })
  },

  /**
   * 跳转到邀请好友页面
   */
  toInvitationCards: function() {
    wx.navigateTo({
      url: '/pages/InvitationCards/InvitationCards',
    })
  },

  /**
   * 跳转到提现
   */
  toWithdrawal: function() {
    wx.navigateTo({
      url: '/pages/withdrawal/withdrawal',
    })
  }

})